package crudfx.container;
import javax.swing.*;
import crudfx.interop.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.border.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class PopupDialog {
    var jPopupMenu:JPopupMenu;
    public var content:UIComponent;
    public var x:Number;
    public var y:Number;
    public var width:Number=200;
    public var height:Number=200;
    public var parent:UIComponent;
    var valid:Boolean=false;
    var body:JamTop;
    init{
        jPopupMenu=new JPopupMenu();
        jPopupMenu.setBorder(new EmptyBorder(0,0,0,0));
        //jPopupMenu.setOpaque(false);
        //popup.addPopupMenuListener(
        var lictener:PopupMenuListener=PopupMenuListener{
            override function popupMenuWillBecomeVisible(e:PopupMenuEvent) {
                }
            override function  popupMenuWillBecomeInvisible(e:PopupMenuEvent){
                if(not valid)return;
                valid=false;
                jPopupMenu.setVisible(false);
                }
            override function  popupMenuCanceled(e:PopupMenuEvent) {
                if(not valid)return;
                valid=false;
                jPopupMenu.setVisible(false);
                }
            };
        jPopupMenu.addPopupMenuListener(lictener);
        body=JamTop{content:bind content};
        jPopupMenu.add(body.getJComponent());
        }
    public function show():Void{
        jPopupMenu.setPreferredSize(new Dimension(width, height));
        valid=true;
        jPopupMenu.show(parent.getJComponent(),x,y);
        //println(jPopupMenu);
        }
    public function hide():Void{
        valid=false;
        jPopupMenu.setVisible(false);
        }
}
